package com.trg.flex.frm.validation
{
	import mx.events.ValidationResultEvent;
	import mx.validators.Validator;

	public class MultiValidator extends Validator
	{
		public function MultiValidator(validators:Array = null)
		{
			super();
			this.validators = validators;
		}
		
		public var validators:Array;
		
		override protected function doValidation(value:Object):Array {
			var result:Array = [];
			
			for each (var validator:Validator in validators) {
				var resultEvent:ValidationResultEvent = validator.validate(value, true);
				if (resultEvent.type == ValidationResultEvent.INVALID) {
					var results:Array = resultEvent.results;
					if (results != null) {
						//remove all elements in the results array
						for (var i:int = results.length - 1; i >= 0; i--) {
							if (results[i] == null)
								results.splice(i, 1);
						}
						result = result.concat(results);
					}
				}
			}
			
			return result;
		}
	}
}